//
//  WTLiveExtendView.m
//  66TV
//
//  Created by ben on 16/8/6.
//  Copyright © 2016年 shifeng. All rights reserved.
//

#import "WTLiveExtendView.h"
#import "Masonry.h"
#import "WTCategories.h"

@interface WTLiveExtendView ()
@property (nonatomic, strong) UIView*                     personInfoVisitorsContainerView;
@end


@implementation WTLiveExtendView
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setup];
    }
    return self;
}

- (void)setup{
    

    self.backButton = ({
        UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
        [button setImage:[UIImage wt_imageWithName:@"wt_play_pull_icon"] forState:UIControlStateNormal];
        [self addSubview:button];
        button;
    });
    
    self.personInfoVisitorsContainerView = ({
        
        UIView* view = [[UIView alloc] init];
        [self addSubview:view];
        view;
    });
    
    self.personInfoView = ({
        WTPlayPersonInfoView* view = [[WTPlayPersonInfoView alloc] init];
        [self.personInfoVisitorsContainerView addSubview:view];
        view;
    });
    
    self.visitorsView = ({
        WTPlayVisitorsView* view = [[WTPlayVisitorsView alloc] init];
        [self.personInfoVisitorsContainerView addSubview:view];
        view;
    });
    
    self.coinView = ({
        WTPlayCoinView* view = [[WTPlayCoinView alloc] init];
        [self addSubview:view];
        view;
    });
    
    self.accountView = ({
        WTPlayAccountView* view = [[WTPlayAccountView alloc] init];
        [self addSubview:view];
        view;
    });
    
    self.beautyToolView = ({
        WXLiveBeautyToolView* view = [[[NSBundle mainBundle] loadNibNamed:@"WXLiveBeautyToolView" owner:self options:nil] lastObject];
        [self addSubview:view];
        view;
    });

    self.chatInputView = ({
        WTPlayChatInputView* view = [[WTPlayChatInputView alloc] init];
        view.alpha = 0;
        [self addSubview:view];
        view;
    });
    
    self.chatRoomView = ({
        WTChatRoomView* view = [[WTChatRoomView alloc] init];
        [self addSubview:view];
        view;
    });
    
    self.giftContainer = ({
        UIView* view = [[UIView alloc] init];
        view.backgroundColor = [UIColor clearColor];
        [self addSubview:view];
        view;
    });
    
    self.barrageView = ({
        WTBarrageView* view = [[WTBarrageView alloc] init];
        [view start];
        [self addSubview:view];
        view;
    });
    
    self.chatBlankButton = ({
        UIButton* view = [UIButton buttonWithType:UIButtonTypeCustom];
        view.alpha = 0;
        view.backgroundColor = [UIColor colorWithWhite:0 alpha:0.01];
        [self addSubview:view];
        view;
    });
    
    [self layout];
}


- (void)layout{
    
    [self.backButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(0);
        make.width.and.height.mas_equalTo(40);
        make.top.mas_equalTo(20);
    }];
    
    [self.personInfoVisitorsContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(40);
        make.top.mas_equalTo(self.backButton.mas_top);
        make.trailing.mas_equalTo(0);
        make.height.mas_equalTo(40);
    }];
    
    [self.personInfoView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.top.and.bottom.mas_equalTo(0);
        make.trailing.mas_equalTo(self.personInfoView.attentionButton.mas_trailing).offset(10);
        make.width.mas_lessThanOrEqualTo(180);
    }];
    
    
    [self.visitorsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.personInfoView.mas_trailing).offset(10);
        make.trailing.mas_equalTo(-10);
        make.bottom.mas_equalTo(self.personInfoView.mas_bottom);
        make.height.mas_equalTo(30);
    }];
    
    [self.coinView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(-12);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(25);
        make.top.mas_equalTo(self.personInfoView.mas_bottom).offset(20);
    }];
    
    [self.accountView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(12);
        make.width.mas_equalTo(160);
        make.height.mas_equalTo(25);
        make.top.mas_equalTo(self.coinView.mas_top);
    }];
    
    [self.beautyToolView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.trailing.mas_equalTo(35);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
        make.top.mas_equalTo(self.accountView.mas_bottom).offset(20);
    }];

    [self.chatBlankButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.and.top.mas_equalTo(0);
        make.bottom.mas_equalTo(-40);
    }];
    
    [self.chatInputView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.and.bottom.mas_equalTo(0);
        make.height.mas_equalTo(0);
    }];
    
    
    [self.giftContainer mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.mas_equalTo(0);
        make.height.mas_equalTo(120);
        make.bottom.mas_equalTo(self.barrageView.mas_top);
    }];
    
    [self.barrageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.and.trailing.mas_equalTo(0);
        make.height.mas_equalTo(60);
        make.bottom.mas_equalTo(self.chatRoomView.mas_top);
    }];
    
    [self.chatRoomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(0);
        make.bottom.mas_equalTo(self.chatInputView.mas_top);
        make.height.mas_equalTo(120);
        make.width.equalTo(self).multipliedBy(0.8);
    }];


    self.beautyToolView.isZhanKai = NO;
    [self handle];
}

#pragma mark handle
- (void)handle{
    
    __weak __typeof(self)weakSelf = self;
    self.chatInputView.block = ^(BOOL isDanmu,NSString* text){
        if(weakSelf.sendToDeductionBlock){
            weakSelf.sendToDeductionBlock(text,isDanmu);
        }
    };
    
//    [self.beautyToolView.backButton addAction:^(UIButton *btn) {
//        
//        weakSelf.beautyToolView.isZhanKai = !weakSelf.beautyToolView.isZhanKai;
//        [UIView animateWithDuration:.25 animations:^{
//            [weakSelf layoutIfNeeded];
//        }];
//    }];
//    
//    [self.beautyToolView.beautyButton addAction:^(UIButton *btn) {
//        
//        weakSelf.beautyToolView.isZhanKai = !weakSelf.beautyToolView.isZhanKai;
//        [UIView animateWithDuration:.25 animations:^{
//            [weakSelf layoutIfNeeded];
//        }];
//        [weakSelf popUpView:KLCPopupHorizontalLayoutCenter v_layout:KLCPopupVerticalLayoutBottom];
//    }];
}

- (void)showOrHide{
    
    NSInteger alpha = 1;
    if(self.backButton.alpha == 1){
        alpha = 0;
    }
    self.backButton.alpha = alpha;
    self.personInfoView.alpha = alpha;
    self.visitorsView.alpha = alpha;
    self.coinView.alpha = alpha;
    self.accountView.alpha = alpha;
    self.chatRoomView.alpha = alpha;
}


@end
